
import random
from Tools.tools import LOG

class PreCondition:

    def __init__(self, testContent):
        self.testContent = testContent

    def parserKeyword(self):
        itemList = self.testContent.split('：')[0].split('_')
        market = itemList[1]
        deal = itemList[2]
        type_ = itemList[3]
        LOG().WARNING(f"{self.testContent.split('：')[0]}的前置条件正在生成")
        LOG().WARNING(f'市场：{market}  买卖方向：{deal}  模块：{type_}')
        return market, deal, type_

    def preCondition(self):
        # 这是前置条件
        market, deal, type_ = self.parserKeyword()
        sentence1 = f'1. 测试账户可做{market}的业务;'
        sentence2 = f'2. 可在{market}进行预埋单执行、业务操作的权限;'
        sentence3 = f'3. 拥有足够的可用资金来进行股票买入;' if '买' in deal else '3. 拥有足够的股票持仓来进行股票卖出委托;'
        sentence4 = f'4. 能够连接到{market}的行情;'
        if type_ in ('策略埋单', '策略拆单'):
            return '\n'.join([sentence1, sentence2, sentence3])
        else:
            return '\n'.join([sentence1, sentence2, sentence3, sentence4])


# 测试运行
if __name__ == '__main__':
    from Frames.testCaseParser import Parser
    Parser().sortedDict()
    for content in Parser().testContentOrderedDict.keys():
        print(PreCondition(content).preCondition())
